let init_train_set = () => {
	let train_set = wx.getStorageSync("train_set")
	if(train_set == "" || train_set.letter_all.length == 0) {
		new_train_set()
	}
	else {
		let app = getApp()
		if (typeof (app) != "undefined") {
			app.data.common_store.train_set = train_set
		}
		else {
		}
	}
	// 检查缓存中是否有记录
	
}

let new_train_set = () => {
	let app = getApp()
	let cs = app.data.common_store
	let train_set = {
		letter_all: [],
		letter_set: [],
	}
	for (let i = 0; i < cs.mw.length; i ++) {
		train_set.letter_all.push({"letter": cs.mw[i], "selected": true})
		train_set.letter_set.push(cs.mw[i])
	}
	cs.train_set = train_set
	syn_train_set()
}

let syn_train_set = () => {
	let app = getApp()
	wx.setStorage({
		key: "train_set",
		data: app.data.common_store.train_set
	})
}

let load_train_set = () => {
	return new Promise((done_fn, fail_fn) => {
		wx.getStorage({
			key: "train_set",
			success(res) {
				let app = getApp()
				app.data.common_store.train_set = res.data
				done_fn(res)
			},
			fail(err) {
				fail_fn(err)
			}
		})
	})
}

module.exports = {
	init_train_set: init_train_set,
	syn_train_set: syn_train_set,
	load_train_set: load_train_set,
}